<template>
	<view>
		<mh-navbar custom :back="true" title="个人信息更改" fixed center zIndex="1010" />
		<view class="container">
			<view class="item-list-wrap">
				<view class="item" @click="updateAavtar()">
					<view class="left">
						头像
					</view>
					<view class="right">
						<view class="rightText">
							<image style="width: 46px; height: 46px; background-color: #eeeeee;border-radius: 25px;" :src="avatar"></image>
						</view>
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view class="item" @click="goUrl('/pages/mine/update_nick_name')">
					<view class="left">
						昵称
					</view>
					<view class="right">
						<view class="rightText">
							<text>{{nickName}}</text>
						</view>
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view class="item" @click="goUrl('/pages/mine/change_pwd')">
					<view class="left">
						修改密码
					</view>
					<view class="right">
						<image src="../../static/img/my/right.png" mode=""></image>
					</view>
				</view>
				<view style="height: 2px;"></view>
				<view class="item">
					<view class="left">
						注册时间
					</view>
					<view class="right">
						<view class="rightText">
							{{registerTime}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar:'',
				nickName:'',
				registerTime:'',
			}
		},
		onShow(){
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.avatar)){
				this.avatar = this.$store.state.vuex_user.avatar;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.nickName)){
				this.nickName = this.$store.state.vuex_user.nickName;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.mobile)){
				this.mobile = this.$store.state.vuex_user.mobile;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.registerTime)){
				this.registerTime = this.$store.state.vuex_user.registerTime;
			}
		},
		methods: {
			goUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			//更改头像
			updateAavtar(){
				debugger
				console.info(this.$store.state.vuex_config.baseUrl)
				let _this = this;
				uni.chooseImage({ // 从本地相册选择图片或使用相机拍照。
					count: 1,//默认选择1张图片
					sizeType: ['original', 'compressed'],//original 原图，compressed 压缩图，默认二者都有
					success:  (res)=> {
						console.log(res.tempFilePaths[0]);//成功则返回图片的本地文件路径列表 tempFilePaths
						uni.uploadFile({//将本地资源上传到开发者服务器
							url: this.$store.state.vuex_config.baseUrl + '/api/user/avatar', //接口地址
							filePath: res.tempFilePaths[0],//图片地址
							name: 'avatarfile',
							header: {
								'Authorization': this.$store.state.vuex_token
							},
							success: (uploadFileRes) => {
								debugger
								let data = JSON.parse(uploadFileRes.data)
								if(data.code == 200){
									this.avatar = data.url;
									 this.$u.vuex('vuex_user.avatar', data.url)
								}
							}
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
.container{
	.item-list-wrap{
		display: flex;
		flex-direction: column;
		.item{
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			height: 50px;
			background: #FFFFFF;
			padding: 0 10px;
			.left{
				
			}
			.right{
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				image{
					width: 20px;
					height: 20px;	
				}
			}
		}
	}
}
</style>
